package com.fz.song.mcos.common;

import com.fz.song.mcos.enums.CodeEnum;
import lombok.Data;

import java.io.Serializable;


@Data
public class R<T> implements Serializable {


    private int code;
    private String msg;
    private T data;

    public R() {
    }

    public R code(int code) {
        this.code = code;
        return this;
    }

    public R msg(String msg) {
        this.msg = msg;
        return this;
    }

    public R data(T data) {
        this.data = data;
        return this;
    }


    public static R ok() {
        CodeEnum ok = CodeEnum.OK;
        return new R().code(ok.getCode()).msg(ok.getMsg());
    }

    public static R fail() {
        CodeEnum fail = CodeEnum.FAIL;
        return new R().code(fail.getCode()).msg(fail.getMsg());
    }

}
